package cn.com.bluemoon.daps.model.core.file.hive;

import cn.com.bluemoon.daps.common.validation.illegal.IllegalChar;
import cn.com.bluemoon.daps.model.core.file.PartitionData;
import cn.com.bluemoon.daps.model.core.file.excel.converter.MyPartitionFieldTypeIntegerStringConverter;
import cn.com.bluemoon.daps.model.entity.DapDataModelTablePartition;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import lombok.Data;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 * <pre>
 *     序号	表英文名	分区字段	字段类型
 * 1	b2b_User_Huanxin_Info	part_m	string
 * 2	b2b_User_Huanxin_Info	part_d	string
 * </pre>
 *
 * @author Jarod.Kong
 * @date 2021/2/5 9:28
 */
@Data
@ColumnWidth(20)
@HeadRowHeight(15)
@ContentRowHeight(20)
public class HivePartitionData extends PartitionData {

    @ExcelProperty("序号")
    @ColumnWidth(8)
    private Integer order;

    //    @NoSqlKeyword(dbtype = DbType.hive, name = "表英文名")
    @IllegalChar(message = "表英文名存在非法字符")
    @ExcelProperty("表英文名")
    @NotNull(message = "表英文名不可为空")
    @Size(max = 64, message = "表英文名不可以大于{max}")
    private String tableName;

    @ExcelProperty("分区字段")
    @NotNull(message = "分区字段不可为空")
    private String partitionFieldName;
    /**
     * 若为分区表，对应的分区类型： 1 String 2 Integer
     */
    @ExcelProperty(value = "字段类型", converter = MyPartitionFieldTypeIntegerStringConverter.class)
    @NotNull(message = "字段类型不可为空")
    private Integer partitionFieldType;

    @ExcelProperty("分区注释")
    private String partitionComment;

    public static HivePartitionData getInstance() {
        return new HivePartitionData();
    }

    @Override
    public HivePartitionData copyDbProperties0(DapDataModelTablePartition dbIndex) {
        setTableName(dbIndex.getTableName());
        setPartitionFieldName(dbIndex.getPartitionFieldName());
        setPartitionFieldType(dbIndex.getPartitionFieldType());
        setPartitionComment(dbIndex.getName());
        return this;
    }
}
